<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="net.ojbk.timeAxis.service.*" import="net.ojbk.timeAxis.po.*" import="java.util.List"%>
<!DOCTYPE HTML>
<html>
    <head>
        <title>Overflow by HTML5 UP</title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <meta name="description" content="" />
        <meta name="keywords" content="" />
        <link href="http://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,300italic" rel="stylesheet" type="text/css" />
        <script src="js/jquery.min.js"></script>
        <script src="js/jquery.poptrox-2.2.js"></script>
        <script src="js/skel.min.js"></script>
        <script src="js/init.js"></script>
        <noscript>
            <link rel="stylesheet" href="css/skel-noscript.css" />
            <link rel="stylesheet" href="css/style.css" />
        </noscript>
    </head>
    
    <%
    boolean isLogin = false;
    String userId = null;
    TimeAxisService service = new TimeAxisService();
    TimeAxis timeAxisInfo = new TimeAxis();
    List<TimeAxisPage> timeAxisPageS = null;
    if ((session != null && session.getAttribute("login") != null && (boolean)session.getAttribute("login"))) { //如果登录
        userId = (String) session.getAttribute("userId");
        List<TimeAxis> timeAxisInfos = service.getAllTimeAxisInfo(userId);
        // 时光轴数据
        if (timeAxisInfos != null && timeAxisInfos.size() > 0)
            timeAxisInfo = timeAxisInfos.get(0);
        
        timeAxisPageS = service.getAllTimeAxisPageInfo(timeAxisInfo.getAxisId());
        System.out.println(timeAxisPageS);
        isLogin = true;
    }
    %>
    
    <body>

        <!-- Header -->
            <section id="header">
                <header>
                    <h1>Time Axis</h1>
                    <p>By HTML5 UP</p>
                </header>
                <footer>
                    <a href="#banner" class="button style2 scrolly">Proceed as anticipated</a>
                </footer>
            </section>
    <% if(isLogin){ %>
        <!-- Banner -->
            <section id="banner">
                <header>
                    <h2><%= timeAxisInfo.getAxisTitile() %></h2>
                </header>
                <p> <%= timeAxisInfo.getAxisInfo() %></p>
                <footer>
                    <a href="#first" class="button style2 scrolly">Act on this Axis</a>
                </footer>
            </section>
            
        <!-- Feature By For -->
        <%
            if (timeAxisPageS != null)
            for (TimeAxisPage tempTimeAxisPage : timeAxisPageS) {
        %>
            <article id="first" class="container box style1 right">
                <a href="http://ineedchemicalx.deviantart.com/art/Time-goes-by-too-fast-335982438" class="image full"><img src="images/pic01.jpg" alt="" /></a>
                <div class="inner">
                    <header>
                        <h2><a href="./time.jsp?timeId=<%= tempTimeAxisPage.getTimeId() %>"><%= tempTimeAxisPage.getTimeTitle() %></a><br />
                        <%= tempTimeAxisPage.getTimeDate() %></h2>
                    </header>
                    <p><%= tempTimeAxisPage.getTimeInfo() %></p>
                </div>
            </article>
        <%
            } else {System.out.println("11111111");}
        %>
        
        <!-- Portfolio -->
            <article class="container box style2">
                <header>
                    <h2>Magnis parturient</h2>
                    <p>Justo phasellus et aenean dignissim<br />
                    placerat cubilia purus lectus.</p>
                </header>
                <div class="inner gallery">
                    <div class="row flush">
                        <div class="3u"><a href="images/fulls/01.jpg" class="image full"><img src="images/thumbs/01.jpg" alt="" title="Ad infinitum" /></a></div>
                        <div class="3u"><a href="images/fulls/02.jpg" class="image full"><img src="images/thumbs/02.jpg" alt="" title="Dressed in Clarity" /></a></div>
                        <div class="3u"><a href="images/fulls/03.jpg" class="image full"><img src="images/thumbs/03.jpg" alt="" title="Raven" /></a></div>
                        <div class="3u"><a href="images/fulls/04.jpg" class="image full"><img src="images/thumbs/04.jpg" alt="" title="I'll have a cup of Disneyland, please" /></a></div>
                    </div>
                    <div class="row flush">
                        <div class="3u"><a href="images/fulls/05.jpg" class="image full"><img src="images/thumbs/05.jpg" alt="" title="Cherish" /></a></div>
                        <div class="3u"><a href="images/fulls/06.jpg" class="image full"><img src="images/thumbs/06.jpg" alt="" title="Different." /></a></div>
                        <div class="3u"><a href="images/fulls/07.jpg" class="image full"><img src="images/thumbs/07.jpg" alt="" title="History was made here" /></a></div>
                        <div class="3u"><a href="images/fulls/08.jpg" class="image full"><img src="images/thumbs/08.jpg" alt="" title="People come and go and walk away" /></a></div>
                    </div>
                </div>
            </article>
    <% } %>
        <section id="footer">
            <ul class="icons">
                <li><a class="icon icon-user solo" onclick="login()"><span>登录</span></a></li>
                <li><a class="icon icon-apple solo" onclick="register()"><span>注册</span></a></li>
                <li><a href="./publishTime.jsp?axisId=<%= timeAxisInfo.getAxisId() %>" class="icon icon-edit solo"><span>发布时光叶片</span></a></li>
                <li><a class="icon icon-compass solo" onclick="modifyMsgPw()"><span>修改密码</span></a></li>
                <li><a class="icon icon-book solo"><span>评论权限管理</span></a></li>
                <li><a class="icon icon-lock solo"><span>展示权限管理</span></a></li>
            </ul>
            <div class="copyright">
                <p>Copyright © <a href="#">师易赛事服务平台</a>  2018. OJBK <a title="师易信息科技有限公司" href="http://www.ojbk.net/" target="_blank">师易信息科技有限公司</a></p>
            </div>
        </section>
        <script type="text/javascript">
            function login() {
                var userId = prompt('请出入用户名:');
                if (userId == '') {
                    alert('请入正确的账号。');
                    return ;
                }
                var userPW = prompt('请输入密码:');
                if (userPW == '') {
                    alert('请入正确的密码。');
                    return ;
                } 
                $.ajax({    
                    url:"LoginAndRegisterServlet", // URL 目标
                    data: {
                        type: 'login',
                        userId: userId,
                        userPW: userPW
                    },
                    type:"POST", 
                    cache:false,
                    dataType:'json',
                    success:function(data){ // 成功调用
                        var json = data;
                        // JSON.stringify(data) // 查看 String 代码
                        if (json.status) {
                            alert("登录成功。");
                            // window.location.href='.' + Pw ;
                            window.location.reload();
                        }
                        else {
                            alert("密码错误。");
                        }
                    },
                    error:function(er){
                        alter(er);
                    }
                });
            }
            // register
            function register() {
                var userId = prompt('请出入用户名:');
                if (userId == '') {
                    alert('请入正确的账号。');
                    return ;
                }
                var userPW = prompt('请输入密码:');
                if (userPW == '') {
                    alert('请入正确的密码。');
                    return ;
                } 
                $.ajax({    
                    url:"LoginAndRegisterServlet", // URL 目标
                    data: {
                        type: 'register',
                        userId: userId,
                        userPW: userPW
                    },
                    type:"POST", 
                    cache:false,
                    dataType:'json',
                    success:function(data){ // 成功调用
                        var json = data;
                        if (json.status) {
                            alert("注册成功。");
                        }
                        else{
                            alert("注册失败。");
                        }
                    },
                    error:function(er){
                        alter(er);
                    }
                });
            }
            // modifyMsgPw
            function modifyMsgPw() {
                var str = prompt('请输入你的新密码:');
                if (str == '') {
                    alert('请正确进行输入。');
                    return ;
                }
                $.ajax({    
                    url:"timeAxisServlet", // URL 目标
                    data: {
                        type: 'modifyMsgPw',
                        newPw: str,
                        axisId: <%= timeAxisInfo.getAxisId() %>
                    },
                    type:"POST", 
                    cache:false,
                    dataType:'json',
                    success:function(data){ // 成功调用
                        var json = data;
                        if (json.status) {
                            alert("修改成功。");
                        }
                        else{
                            alert("修改失败。");
                        }
                    },
                    error:function(er){
                        alter(er);
                    }
                });
            }
        </script>
    </body>
</html>